package com.wr.springbootadmin.config;

import com.wr.springbootadmin.common.ResponseResult;
import com.wr.springbootadmin.common.ResultCode;
import com.wr.springbootadmin.customizeExceptions.CustomizeException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 王瑞
 * @description: 全局异常捕获类  可以随时新增
 * @date 2020/12/24  15:51
 */

@RestControllerAdvice
public class GlobalExceptController {


    /*抛出自定义异常 走这里处理*/
    @ExceptionHandler(value = CustomizeException.class)
    public ResponseResult customizeExceptionHandler(CustomizeException ce){
        return ResponseResult.failed(ce);
    }

    //-----------------------------1,AuthenticationException 认证异常-----------------------------------------------------

/*

    */
/*一些常见的shiro异常： 不正确的凭证  *//*

    @ExceptionHandler(value = IncorrectCredentialsException.class)
    public ResponseResult shiroIncorrectCredentialsException(IncorrectCredentialsException ie){
        return ResponseResult.failed(ResultCode.INVALID_CERTIFICATE);
    }

    */
/*一些常见的shiro异常： 凭证过期*//*

    @ExceptionHandler(value = ExpiredCredentialsException.class)
    public ResponseResult shiroExpiredCredentialsException(ExpiredCredentialsException ie){
        return ResponseResult.failed(ResultCode.INVALID_EXPIRED);
    }


    */
/*一些常见的shiro异常： ConcurrentAccessException: 并发访问异常（多个用户同时登录时抛出）*//*

    @ExceptionHandler(value = ConcurrentAccessException.class)
    public ResponseResult shiroConcurrentAccessException(ConcurrentAccessException ie){
        return ResponseResult.failed(ResultCode.MULTIPLE_ONLOGIN);
    }

    */
/*一些常见的shiro异常： 未知的账号*//*

    @ExceptionHandler(value = UnknownAccountException.class)
    public ResponseResult shiroUnknownAccountException(UnknownAccountException ie){
        return ResponseResult.failed(ResultCode.UNKNOWN_ACCOUNT);
    }

    */
/*一些常见的shiro异常： 认证次数超过限制*//*

    @ExceptionHandler(value = ExcessiveAttemptsException.class)
    public ResponseResult shiroExcessiveAttemptsException(ExcessiveAttemptsException ie){
        return ResponseResult.failed(ResultCode.EXCESSIVE_ATTEMPTS);
    }

    */
/*一些常见的shiro异常： 禁用的账号*//*

    @ExceptionHandler(value = DisabledAccountException.class)
    public ResponseResult shiroDisabledAccountException(DisabledAccountException ie){
        return ResponseResult.failed(ResultCode.DISABLED_ACCOUNT);
    }

    */
/*一些常见的shiro异常： 账号被锁定*//*

    @ExceptionHandler(value = LockedAccountException.class)
    public ResponseResult shiroLockedAccountException(LockedAccountException ie){
        return ResponseResult.failed(ResultCode.LOCKED_ACCOUNT);
    }

    */
/*一些常见的shiro异常： 使用了不支持的Token*//*

    @ExceptionHandler(value = UnsupportedTokenException.class)
    public ResponseResult shiroUnsupportedTokenException(UnsupportedTokenException ie){
        return ResponseResult.failed(ResultCode.INVALID_TOKEN);
    }




    //-----------------------------1,AuthorizationException 授权异常-----------------------------------------------------

    */
/*一些常见的shiro异常： 抛出以指示请求的操作或对请求的资源的访问是不允许的。也就是未授权*//*

    @ExceptionHandler(value = UnauthorizedException.class)
    public ResponseResult shiroUnauthorizedException(UnauthorizedException ie){
        return ResponseResult.failed(ResultCode.UNAUTHORIZED);
    }

    */
/*一些常见的shiro异常： 当尚未完成成功认证时，尝试执行授权操作时引发异常。。也就是未认证*//*

    @ExceptionHandler(value = UnauthenticatedException.class)
    public ResponseResult shiroUnauthenticatedException(UnauthenticatedException ie){
        return ResponseResult.failed(ResultCode.UNANTHENTICATED);
    }


*/


    /*后端程序出错时其他异常统一走这里*/
    //@ExceptionHandler(value = RuntimeException.class)
    public ResponseResult serviceException(RuntimeException e){
        return ResponseResult.failed(ResultCode.SERVICE_ERROR.getCode(),e.getMessage());
    }




}
